package com.xh.bussiness.teachbook.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xh.bussiness.teachbook.dao.TeachingBookStudentQuestionResultMapper;
import com.xh.bussiness.teachbook.model.TeachingBookStudentQuestionResult;
import com.xh.bussiness.teachbook.model.TeachingBookStudentResult;
import com.xh.bussiness.teachbook.service.ITeachingBookStudentQuestionResultService;
import com.xh.bussiness.teachbook.service.ITeachingBookStudentResultService;
import com.xh.core.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * <p>
 *
 * </p>
 *
 * @author Pitt zhang
 * @since 2019/9/11
 */
@Service
public class TeachingBookStudentQuestionResultServiceImpl extends BaseServiceImpl<TeachingBookStudentQuestionResultMapper,TeachingBookStudentQuestionResult> implements ITeachingBookStudentQuestionResultService {

    @Autowired
    private ITeachingBookStudentResultService studentResultService;

    @Override
    public void deleteByStudentResultId(String studentResultId, List<Integer> questionSourceTypes) {
        this.dao.deleteByStudentResultId(studentResultId,questionSourceTypes);
    }

    @Override
    public TeachingBookStudentQuestionResult queryOneByParam(String studentId, String teachingBookId, String questionId,Integer questionSourceType) {
        QueryWrapper<TeachingBookStudentResult> studentResultQueryWrapper = new QueryWrapper<>();
        studentResultQueryWrapper.eq("teaching_book_id", teachingBookId);
        studentResultQueryWrapper.eq("student_id", studentId);
        TeachingBookStudentResult studentResult = studentResultService.selectOne(studentResultQueryWrapper, TeachingBookStudentResult.class);
        if (studentResult == null) {
            return null;
        }
        //作答试题结果
        QueryWrapper<TeachingBookStudentQuestionResult> studentQuestionResultQueryWrapper = new QueryWrapper<>();
        studentQuestionResultQueryWrapper.eq("student_result_id", studentResult.getId());
        studentQuestionResultQueryWrapper.eq("question_id", questionId);
        studentQuestionResultQueryWrapper.eq("question_source_type", questionSourceType);
        TeachingBookStudentQuestionResult questionResult = this.selectOne(studentQuestionResultQueryWrapper, TeachingBookStudentQuestionResult.class);
        return questionResult;
    }
}
